import type { RouteRecordRaw } from 'vue-router'

const pageModules = import.meta.glob('/src/views/**/config.ts', {
  eager: true,
  import: 'default'
})

const compModules = import.meta.glob('/src/views/**/index.vue')

export const routes = Object.entries(pageModules).map(([pagePath, config]) => {
  const path =
    pagePath.replace('/src/views/', '').replace('/config.ts', '') || '/'
  const name = path.split('/').filter(Boolean).join('-') || 'index'
  const compPath = pagePath.replace('config.ts', 'index.vue')
  return {
    path,
    name,
    component: compModules[compPath],
    mata: config
  } as RouteRecordRaw
})
